package de.pass.ch.junit;

import static java.lang.Integer.MAX_VALUE;
import static org.junit.Assert.assertEquals;

import java.util.Random;

import org.junit.Test;

import de.pass.ch.graph.edge.Edge;
import de.pass.ch.graph.node.UpNode;

public class TestUpNode {

	@Test
	public void testUpNodeMethods() {

		int runs = 100000;
		int intMax = (MAX_VALUE >> 1);
		int shMax = (1 << 16) - 1;

		Random r = new Random();

		int level = 0;
		// int firstEdge = 0;
		int firstLevelEdgeOffset = 0;
		// int lastEdgeOffset = 0;
		int pqElement = 0;
		boolean target = false;
		UpNode node = null;

		for (int i = 0; i < runs; i++) {

			level = r.nextInt(intMax);
			// firstEdge = r.nextInt(intMax);
			firstLevelEdgeOffset = r.nextInt(shMax);
			// lastEdgeOffset = r.nextInt(shMax);
			pqElement = r.nextInt(intMax);
			target = r.nextBoolean();

			node = new UpNode(level, firstLevelEdgeOffset, pqElement,
					new Edge[0]);
			node.setTarget(target);
			// node.setLastEdge(firstEdge + lastEdgeOffset);

			assertEquals(level, node.getLevel());
			// assertEquals(firstEdge, node.getFirstEdge());
			// assertEquals(firstEdge + firstLevelEdgeOffset,
			// node.getFirstLevelEdge());
			// assertEquals(firstEdge + lastEdgeOffset, node.lastEdge());
			assertEquals(pqElement, node.getPQElement());
			assertEquals(target, node.isTarget());

			level = r.nextInt(intMax);
			node.setLevel(level);

			assertEquals(level, node.getLevel());
			// assertEquals(firstEdge, node.getFirstEdge());
			// assertEquals(firstEdge + firstLevelEdgeOffset,
			// node.getFirstLevelEdge());
			// assertEquals(firstEdge + lastEdgeOffset, node.lastEdge());
			assertEquals(pqElement, node.getPQElement());
			assertEquals(target, node.isTarget());

			// firstEdge = r.nextInt(intMax);
			// node.setFirstEdge(firstEdge);

			assertEquals(level, node.getLevel());
			// assertEquals(firstEdge, node.getFirstEdge());
			// assertEquals(firstEdge + firstLevelEdgeOffset,
			// node.getFirstLevelEdge());
			// assertEquals(firstEdge + lastEdgeOffset, node.lastEdge());
			assertEquals(pqElement, node.getPQElement());
			assertEquals(target, node.isTarget());

			firstLevelEdgeOffset = r.nextInt(shMax);
			// node.setFirstLevelEdge(firstEdge + firstLevelEdgeOffset);

			assertEquals(level, node.getLevel());
			// assertEquals(firstEdge, node.getFirstEdge());
			// assertEquals(firstEdge + firstLevelEdgeOffset,
			// node.getFirstLevelEdge());
			// assertEquals(firstEdge + lastEdgeOffset, node.lastEdge());
			assertEquals(pqElement, node.getPQElement());
			assertEquals(target, node.isTarget());

			// lastEdgeOffset = r.nextInt(shMax);
			// node.setLastEdge(firstEdge + lastEdgeOffset);

			assertEquals(level, node.getLevel());
			// assertEquals(firstEdge, node.getFirstEdge());
			// assertEquals(firstEdge + firstLevelEdgeOffset,
			// node.getFirstLevelEdge());
			// assertEquals(firstEdge + lastEdgeOffset, node.lastEdge());
			assertEquals(pqElement, node.getPQElement());
			assertEquals(target, node.isTarget());

			pqElement = r.nextInt(intMax);
			node.setPQElement(pqElement);

			assertEquals(level, node.getLevel());
			// assertEquals(firstEdge, node.getFirstEdge());
			// assertEquals(firstEdge + firstLevelEdgeOffset,
			// node.getFirstLevelEdge());
			// assertEquals(firstEdge + lastEdgeOffset, node.lastEdge());
			assertEquals(pqElement, node.getPQElement());
			assertEquals(target, node.isTarget());

		}

	}

}
